<!doctype html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<title>我的关注</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<include file="Public:iframe_header"/>
		<style type="text/css">
			*{
				font-size: 95%;
			}
			table{
				width: 100%;
				text-align: center;
	            margin: 10px auto;
	            border-collapse: separate;
	            border-spacing: 0;
	            border-collapse: separate;
	            border-spacing: 0;
	            border: 2px #000;
				
			}
			table tr td{
				margin: 5px auto;
				border-bottom: 1px solid #AAAAAA;
			}
			
			button{
				color: white;
				background-color: orange;
			}
		</style>
		<style type="text/css">

* {
    font-size: 95%;
    font-family: haettenschweiler;
}

html
 {
    height: 100%;
    padding: 0;
    margin: 0;
    background-color: #fff;
   
}
body{
    padding: 0;
    margin: 0;
    background-color: #fff;
}
button{
    background-color: orange;
}

.tab-page{
    width: 100%;
    margin: 10px auto;
    text-align: center;
}
.tab-page a{
    padding: 2px 8px;
    border: 1px solid #C8C7CC;
}

.a-page{
    background-color: blue;
    color: white;
}
.qy-cont {

    background-color: white;
    width: 100%;
}
.qy-tab{
    width: 100%;
    height:calc(60% - 60px);
    
    overflow-y: scroll;
    
}

.div-jz{
    text-align: center;
}

.div-jz button{
    text-align: center;
    border: 1px solid #F4F4F4;
    color: #C8C7CC;
    background-color: #F4F4F4;
}

.btn3{
    /*background-color:#00B1D7*/
}

    </style>
	</head>

	<body>
		<table border="0" cellspacing="10" cellpadding="10" align="center" >
	            <tr>
	                <th class="h1">名称</th>
	                <th class="t2">地址</th>
	                <th class="t3">操作</th>
	            </tr>
	    </table>
		<div class="mui-content" align="center" style="background-color: #fff;">
		    <table id="table" border="0" cellspacing="0" cellpadding="0">
		    	<volist name="attention_result" id="vo">
	                <tr>
	                    <td class="t1" _href="{$vo.url}" id="'+data[i].id+'" onclick="return_company(this)" verification_login="true">{$vo.name}</td>
	                    <td class="t2" _href="{$vo.url}" id="'+data[i].id+'" onclick="return_company(this)" verification_login="true">{$vo.path_tem}</td>
	                    <if condition="$vo.is_attention eq 0 || $vo.is_attention eq -1">
	                        <td class="btn1" style="width: 25%;" onclick="change_class(this)" <if condition="$vo.is_attention eq -1">status="1"<else />status="0"</if>company_id="{$vo.id}"><button>关注</button></td>
	                    </if>
	                    <if condition="$vo.is_attention eq 1">
	                        <td class="btn3" style="width: 25%;" onclick="change_class(this)"  status="-1" company_id="{$vo.id}"><button>取消关注</button></td>
	                    </if>
	                </tr>
            	</volist>
		    </table>
		    <if condition="$click_for_more">
	            <div id="click_for_more" class="div-jz" style="" page="1">
	                <button>点击加载更多</button>
	            </div>
        	</if> 
		</div>
	</body>

	<script>
		$("#click_for_more").click(function(){
	        var page=$(this).attr('page');
	        page = parseInt(page);
	        var sear_name_val = $('input[name="sear_name"]').val();
	        page += 1;

	        var formData = new FormData();
	        formData.append('page',page);
	        formData.append('name',sear_name_val);

	        var index = parent.wait();
	        $.ajax({
	            url:"{:url('Center/care')}",
	            type:'POST',
	            data:formData,
	            async:false,
	            processData:false,
	            contentType:false,
	            success:function(result){
	                parent.close_wait(index);
	                if(result.msg.length == 0){
	                    $("#click_for_more").remove();
	                    return false;
	                }else{
	                    $("#click_for_more").attr('page',page);
	                }

	                var html = '';
	                for(var i=0;i<result.msg.length;i++){
	                    html += '<tr>';
	                    html += '<td class="t1" verification_login="true" id="'+result.msg[i].id+'" _href="'+result.msg[i].url+'" onclick="return_company(this)">';
	                    html += result.msg[i].name;
	                    html += '</td>';
	                    html += '<td class="t2" verification_login="true" id="'+result.msg[i].id+'" _href="'+result.msg[i].url+'" onclick="return_company(this)">'+result.msg[i].path_tem+'</td>';
	                    if(result.msg[i].is_attention == '0' || result.msg[i].is_attention == '-1'){
	                        html += '<td class="btn1" style="width: 25%;" onclick="change_class(this)"'; 
	                        if(result.msg[i].is_attention == '-1'){
	                            html += 'status="1"';
	                        }else{
	                            html += 'status="0"';
	                        } 
	                        html += 'company_id="'+result.msg[i].id+'"><button>关注</button></td>';
	                    }
	                    if(result.msg[i].is_attention == '1'){
	                        html += '<td class="btn3" style="width: 25%;" onclick="change_class(this)"  status="-1" company_id="'+result.msg[i].id+'"><button>取消关注</button></td>';
	                    }
	                    html += '</tr>';
	                }

	                $('#table').append(html);
	            }
	        });

	    });

	    function change_class(obj){
        var status = $(obj).attr('status');
        var company_id = $(obj).attr('company_id');
        var class_name = $(obj).attr('class');
        var bool = false;

        var formData = new FormData();
        formData.append('status',status);
        formData.append('company_id',company_id);

        $.ajax({
            url:"{:url('Company/follow')}",
            type:'POST',
            data:formData,
            async:false,
            processData:false,
            contentType:false,
            success:function(result){
                if(result.code == 0){
					parent.tips(result.msg);
                    bool = true;
                }
            }

        });

        if(bool){
            return false;
        }

        $(obj).removeClass('btn1');
        $(obj).removeClass('btn3');
        //$(obj).attr('status','');

        if(class_name == 'btn1'){
            $(obj).attr("class","btn3");
            $(obj).find('button').text("取消关注");
            $(obj).attr('status','-1');
        }else{
            $(obj).attr("class","btn1");
            $(obj).attr('status','1');
            $(obj).find('button').text("关注");
        }
    }

    //检测是否有权限
     function return_company(obj){
         var a_href = $(obj).attr('_href');
         var id = $(obj).attr('id');

         var formData = new FormData();
         formData.append('id',id);

         $.ajax({
             url:a_href,
             type:'POST',
             data:formData,
             async:false,
             processData:false,
             contentType:false,
             success:function(result){
                 if(result.code == 0){
					 parent.tips(result.msg);
                     return false;
                 }
                 window.location.href=result.url;
             }

         });
     }
	</script>
</html>